<!DOCTYPE html>
<html lang="cmn-Hans" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的消息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" th:href="@{/frame/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/frame/flyres/css/global.css}">
</head>
<body>
<div th:replace="customer/top :: topBar"></div>
<div class="layui-container fly-marginTop fly-user-main">
    <div th:replace="customer/left :: leftBar"></div>
    <div class="fly-panel fly-panel-user" pad20 style="background-color: rgb(215,215,215);padding-top: 20px;">
        <!--<div class="fly-none">您暂时没有最新消息</div>-->
        <div class="layui-row layui-col-space15">
            <div class="layui-card" th:each="item : ${mymsgs.list}">
                <div class="layui-card-header">
                    <div class="layui-row">
                        <div th:if="${session.current_customer.phone eq item.sender.phone}">
                            <div class="layui-col-md1">您向</div>
                            <div class="layui-col-md6">
                                <a class="fly-nav-avatar" th:href="@{'/customer/home?uid='+${item.receiver.phone * 6}}">
                                    <img th:src="@{'/picture/getAvatar?fileName='+${item.receiver.avatar}}"/>
                                    [[${item.receiver.username}]]
                                </a>
                            </div>
                            <div class="layui-col-md2">发送的消息</div>
                        </div>
                        <div th:unless="${session.current_customer.phone eq item.sender.phone}">
                            <div class="layui-col-md1">来自</div>
                            <div class="layui-col-md6">
                                <a class="fly-nav-avatar" th:href="@{'/customer/home?uid='+${item.sender.phone * 6}}">
                                    <img th:src="@{'/picture/getAvatar?fileName='+${item.sender.avatar}}"/>
                                    [[${item.sender.username}]]
                                </a>
                            </div>
                            <div class="layui-col-md1">的消息</div>
                            <div class="layui-col-md1">
                                <button class="layui-btn layui-btn-normal"
                                        th:onclick="'showedit('+${item.sender.phone * 6}+')'">回复
                                </button>
                            </div>
                        </div>
                        <div class="layui-col-md3" style="text-align: right" th:text="${item.stime}"></div>
                    </div>
                </div>
                <div class="layui-card-body" th:utext="${item.getContent()}"></div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body" align="center">
                    <div id="test1"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/frame/layui/layui.js}"></script>
<script>
    layui.cache.page = 'user';
    layui.cache.user = {
        username: '游客'
        , uid: -1
        , avatar: '[[@{/frame/flyres/images/avatar/00.jpg}]]'
        , experience: 83
        , sex: '男'
    };
    layui.config({
        version: "3.0.0"
        , base: '/frame/flyres/mods/'
    }).extend({
        fly: 'index'
    }).use(['fly', 'element', 'laypage'], function () {
        const element = layui.element;
        const laypage = layui.laypage;
        const $ = layui.$;
        $(function () {
            $('#leftbar li').eq(4).addClass('layui-this');
        });

        laypage.render({
            elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
            , count: [[${mymsgs.total}]] //数据总数，从服务端得到
            , curr: [[${mymsgs.pageNum}]]
            , limit: [[${mymsgs.pageSize}]]
            , limits: [5, 10, 20, 30, 40, 50]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , jump: function (obj, first) {
                //obj包含了当前分页的所有参数，比如：
                // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                // console.log(obj.limit); //得到每页显示的条数

                //第一次载入页面时，视为一次跳转，此时first的值为true
                //其他时候，first的值为undefined
                //如果分页是跳转型的（页面有刷新的那种），first为true的跳转不要执行，否则页面将会一直跳转
                //刚进入页面时，first为true，执行跳转后，进入新的页面，first又为true，继续跳转。。。。。。
                //Ajax型不需要考虑
                if (!first) {
                    location.href = '[[@{/message/showMessage}]]?index=' + obj.curr + '&pageSize=' + obj.limit;
                }
            }
        });

        window.showedit = function (other) {
            const index = layer.open({
                type: 2
                , title: '发送消息'
                , content: '/message/sendMessagePage'
                , area: ['550px', '406px']
                , success: function (layero, index) {
                    const iframe = window['layui-layer-iframe' + index];
                    iframe.deliverValue(other);
                }
            });
        }
    });
</script>
</body>
</html>